package com.xzz.controller;

import com.xzz.doc.CourseDoc;
import com.xzz.dto.CourseSearchDto;
import com.xzz.result.JSONResult;
import com.xzz.result.PageList;
import com.xzz.service.ICourseEsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/search")
public class CourseEsController {

    @Autowired
    private ICourseEsService courseEsService;

    /*
    * 保存数据到ES
     */
    @PostMapping("/saveCourse")
    public JSONResult saveCourseDoc(@RequestBody CourseDoc courseDoc){
        courseEsService.saveCourseDoc(courseDoc);
        return JSONResult.success();
    }

    /*
     *  用ES高级搜索课程
     */
    @PostMapping("/course")
    public JSONResult searchCourse(@RequestBody CourseSearchDto dto){
        PageList<CourseDoc> courseDocs = courseEsService.searchCourse(dto);
        return JSONResult.success(courseDocs);
    }
}
